package com.evan.review.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.evan.review.R;

/**
 * Fragment生命周期演示页面
 * 用于展示各种Fragment生命周期场景
 */
public class FragmentActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "FragmentActivity";
    private TextView tvDescription;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);
        
        initViews();
    }
    
    private void initViews() {
        tvDescription = findViewById(R.id.tv_description);
        
        Button btnBasicLifecycle = findViewById(R.id.btn_basic_lifecycle);
        Button btnBackStack = findViewById(R.id.btn_back_stack);
        Button btnViewPager = findViewById(R.id.btn_viewpager);
        Button btnCommunication = findViewById(R.id.btn_communication);
        Button btnDialogFragment = findViewById(R.id.btn_dialog_fragment);
        
        // 所有功能按钮已实现
        btnBasicLifecycle.setOnClickListener(this);
        btnBackStack.setOnClickListener(this);
        btnViewPager.setOnClickListener(this);
        btnCommunication.setOnClickListener(this);
        btnDialogFragment.setOnClickListener(this);
    }
    
    @Override
    public void onClick(View v) {
        int id = v.getId();
        
        if (id == R.id.btn_basic_lifecycle) {
            // 基本生命周期演示
            startActivity(new Intent(this, BasicLifecycleActivity.class));
        } else if (id == R.id.btn_back_stack) {
            // 返回栈演示
            startActivity(new Intent(this, BackStackActivity.class));
        } else if (id == R.id.btn_viewpager) {
            // ViewPager中的Fragment生命周期
            startActivity(new Intent(this, ViewPagerActivity.class));
        } else if (id == R.id.btn_communication) {
            // Fragment通信方式演示
            startActivity(new Intent(this, CommunicationActivity.class));
        } else if (id == R.id.btn_dialog_fragment) {
            // DialogFragment演示
            startActivity(new Intent(this, DialogFragmentActivity.class));
        }
    }
} 